home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2001 January / Game.EXE_01_2001.iso / demos / Blade of Darkness / data1.cab / Program_Executable_Files / Lib / darfuncs.py < prev    next >
Encoding:
Text File  |  2000-11-16  |  21.8 KB  |  809 lines

  1. ###########################################################################
  2. ###
  3. ###        The dark functions of hell come true in this file
  4. ###      Beaware little coder, the force keep a power inside the
  5. ###    hell and your nightmares will bless your unholly heart with 
  6. ###                       damns and doom over the
  7. ###
  8. ###                |\   /\  |\   - | |  |\|  /  /
  9. ###                | | |__| |_| |_ | |  | | |   \
  10. ###                |/  |  | |\  |  |_|  | |  \  /
  11. ###                 the cutting edge is bladeness
  12. ###
  13. ###########################################################################
  14.  
  15. import Bladex
  16. import AuxFuncs
  17. import EnemyTypes
  18. import Sparks
  19. import Actions
  20. import math
  21. import Breakings
  22. import types
  23. import Reference
  24. import Blood
  25. import SolidMask
  26. import ObjStore
  27. import GameStateAux
  28. import os
  29. import Blood
  30. import ItemTypes
  31. #------------------------------------------------------------------------#
  32. ActualLevel = Bladex.GetCurrentMap()
  33. ############ Misc camera fucs ############ 
  34.  
  35. def Cafin(entity_name, camera_element, node):  
  36.   cam = Bladex.GetEntity("Camera")  
  37.  
  38.   if node==1:
  39.      cam.SType = 0
  40.      cam.ETarget = "Player1"
  41.      cam.TType = 2
  42.      cam.CameraClearPath(0)
  43.      cam.CameraClearPath(1)
  44.      
  45.   
  46.  
  47. def BackPlayer():
  48.     Cam = Bladex.GetEntity("Camera")
  49.     Cam.SetPersonView("Player1")
  50.  
  51. def ChangePointOfView(ox2, oy2, oz2, time,person="Player1"):
  52.  
  53.     cam=Bladex.GetEntity("Camera")
  54.  
  55.     ox1 = cam.Position[0]
  56.     oy1 = cam.Position[1]
  57.     oz1 = cam.Position[2]
  58.  
  59.     #Path objetivo
  60.     cam.AddCameraNode(0, time, ox1, oy1, oz1)
  61.     cam.AddCameraNode(0, time/2.0, ox2, oy2, oz2)
  62.     cam.AddCameraNode(0, time/2.0, (ox1+ox2)/2.0, (oy1+oy2)/2.0, (oz1+oz2)/2.0)
  63.     
  64.     cam.ETarget = person
  65.     cam.TType = 2
  66.  
  67.     cam.SType=1
  68.     cam.CameraStartPath(0)    
  69.     cam.ChangeNodeFunc=Cafin
  70.  
  71.  
  72. def ChangeCam(ox2, oy2, oz2,tx2,ty2,tz2, time,CafinProx):
  73.  
  74.     cam=Bladex.GetEntity("Camera")
  75.  
  76.     ox1 = cam.Position[0]
  77.     oy1 = cam.Position[1]
  78.     oz1 = cam.Position[2]
  79.     
  80.     
  81.     tx1 = cam.TPos[0]
  82.     ty1 = cam.TPos[1]
  83.     tz1 = cam.TPos[2]
  84.     
  85.     
  86.     #Path objetivo
  87.     cam.AddCameraNode(0, time, ox1, oy1, oz1)
  88.     cam.AddCameraNode(0, time/2.0, ox2, oy2, oz2)
  89.     cam.AddCameraNode(0, time/2.0, (ox1+ox2)/2.0, (oy1+oy2)/2.0, (oz1+oz2)/2.0)
  90.  
  91.     cam.AddCameraNode(1, time, tx1, ty1, tz1)
  92.     cam.AddCameraNode(1, time/2.0, tx2, ty2, tz2)
  93.     cam.AddCameraNode(1, time/2.0, (tx1+tx2)/2.0, (ty1+ty2)/2.0, (tz1+tz2)/2.0)
  94.     
  95.     cam.ETarget = "Player1"
  96.     cam.SType=1
  97.     
  98.     cam.TType=1
  99.     cam.CameraStartPath(0)    
  100.     cam.ChangeNodeFunc=CafinProx
  101.  
  102.  
  103. def InitGiroCamera():
  104.         cam=Bladex.GetEntity("Camera")
  105.         VecRot = 2*cam.TPos[0]-cam.Position[0], 2*cam.TPos[1]-cam.Position[1], 2*cam.TPos[2]-cam.Position[2]
  106.         cam.ESource = "Player1"
  107.         cam.SType   = 2
  108.         cam.TType   = 0
  109.         cam.TPos    = VecRot
  110.         
  111.         
  112. def GiraCamara(AngleVariation):
  113.         cam          = Bladex.GetEntity("Camera")
  114.         VecRot       = cam.TPos[0]-cam.Position[0], cam.TPos[1]-cam.Position[1], cam.TPos[2]-cam.Position[2]
  115.         vtpos        = VecRot[0]*math.cos(AngleVariation)-VecRot[2]*math.sin(AngleVariation), VecRot[0], VecRot[0]*math.sin(AngleVariation)+VecRot[2]*math.cos(AngleVariation)
  116.         cam.TPos     = vtpos[0]+cam.Position[0], cam.TPos[1], vtpos[2]+cam.Position[2]
  117.  
  118. ############ Deaths and limbs ############
  119.  
  120. DeathState = 0     # CARLOS : NO GRABAR ESTO, no es necesario
  121. DeathFile  = None  # CARLOS : NO GRABAR ESTO, no es necesario
  122.  
  123. def DetieneArmaMuerto(obj_name):
  124.     global DeathFile
  125.     if DeathFile:
  126.         o = Bladex.GetEntity(obj_name)
  127.         o.OnStopFunc=None
  128.         DeathFile.write("o = Bladex.CreateEntity('" +obj_name+"','"+o.Kind+"',"+str(o.Position[0])+","+str(o.Position[1])+","+str(o.Position[2])+",'Weapon')\n")
  129.         DeathFile.write("o.Orientation = "+str(o.Orientation[0])+","+str(o.Orientation[1])+","+str(o.Orientation[2])+","+str(o.Orientation[3])+"\n")
  130.         DeathFile.write("ItemTypes.ItemDefaultFuncs(o)\n\n")
  131.     
  132.     
  133. def DetieneMutilacion(obj_name):
  134.     global DeathFile
  135.     if DeathFile:
  136.         o = Bladex.GetEntity(obj_name)
  137.         o.OnStopFunc=None
  138.         DeathFile.write("\no = "+o.Data[0]+".SeverLimb("+str(o.Data[1])+")\n")
  139.         DeathFile.write("o.Stop()\n")
  140.         DeathFile.write("o.Position    = "+str(o.Position   [0])+","+str(o.Position   [1])+","+str(o.Position   [2])+"\n")
  141.         DeathFile.write("o.Orientation = "+str(o.Orientation[0])+","+str(o.Orientation[1])+","+str(o.Orientation[2])+","+str(o.Orientation[3])+"\n")
  142.     
  143.  
  144. def GrabarLaSangre(x,y,z):
  145.     global DeathFile
  146.     if DeathFile:
  147.         DeathFile.write("Bladex.CreateEntity('BloodPool','Entity Pool',"+str(x)+","+str(y)+","+str(z)+")\n")
  148.  
  149. def CloseDeathFile():
  150.     global DeathFile
  151.     if DeathFile:
  152.         print "closing 'death.py'..."
  153.         DeathFile.close()
  154.         DeathFile = None
  155.         os.rename("pak/deaths.py_","pak/deaths.py")
  156.         Blood.AfterCreateBlood = None
  157.     
  158.  
  159. def MuertoyTroceado2(name,trozos):
  160.     muertoint2=Bladex.GetEntity(name)
  161.     muertoint2.CastShadows = 0
  162.     muertoint2.SetOnFloor()
  163.     muertoint2.Life = 0
  164.     for i in trozos:
  165.         mut = muertoint2.SeverLimb(i)
  166.         if mut:
  167.             mut.Data = (muertoint2.Name,i)
  168.             mut.OnStopFunc=DetieneMutilacion
  169.  
  170. muertonum = 0
  171.     
  172.  
  173. def MuertoyTroceado(x,y,z,raze,weapon,trozos,angul=2.19288423389,MeshName=None):
  174.     global ActualLevel
  175.     global muertonum
  176.     global DeathState
  177.     global DeathFile
  178.     
  179.     if DeathState:
  180.         return
  181.  
  182.     if not DeathFile:
  183.         if "deaths.py" in os.listdir("./pak/"):
  184.             execfile("pak/deaths.py")
  185.             DeathState = 1
  186.             return
  187.         print "Creating 'deaths.py'..."
  188.         DeathFile = open("pak/deaths.py_","w")
  189.         DeathFile.write("import Bladex\nimport ItemTypes \n\n")
  190.         DeathFile.write("print 'loading deaths...'\n\n\n")
  191.         Blood.AfterCreateBlood = GrabarLaSangre
  192.  
  193.     if weapon != "" :
  194.         armamuertoint2=Bladex.CreateEntity(ActualLevel+"WeapDeath"+`muertonum`, weapon, 0, 0, 0,"Weapon")
  195.         ItemTypes.ItemDefaultFuncs(armamuertoint2)
  196.         armamuertoint2.OnStopFunc=DetieneArmaMuerto
  197.         
  198.     muertoint2=Bladex.CreateEntity(ActualLevel+"GuyInPieces"+`muertonum`, raze, x, y, z,"Person")
  199.     if MeshName:
  200.         muertoint2.SetMesh(MeshName)
  201.     muertoint2.Angle=angul
  202.     if weapon != "" :
  203.         Actions.TakeObject(muertoint2.Name, armamuertoint2.Name)
  204.         print "The guy ",muertoint2.Name," got a gun named ",armamuertoint2.Name
  205.     else:
  206.         print "The guy ",muertoint2.Name,"is armless"
  207.     EnemyTypes.EnemyDefaultFuncs(muertoint2)
  208.     #Bladex.AddScheduledFunc(Bladex.GetTime()+90.0, MuertoyTroceado2, (muertoint2.Name,trozos))
  209.     MuertoyTroceado2(muertoint2.Name,trozos)
  210.     
  211.     DeathFile.write(muertoint2.Name+" = "+"Bladex.CreateEntity('"+muertoint2.Name+"','"+muertoint2.Kind+"',"+str(muertoint2.Position[0])+","+str(muertoint2.Position[1])+","+str(muertoint2.Position[2])+",'Person'")
  212.     if MeshName:
  213.         DeathFile.write(",'"+MeshName+"')\n\n")
  214.     else:
  215.         DeathFile.write(")\n\n")
  216.         
  217.     DeathFile.write(muertoint2.Name+".Angle = "+str(angul)+"\n")
  218.     DeathFile.write(muertoint2.Name+".Life = 0\n")
  219.     DeathFile.write(muertoint2.Name+".SetOnFloor()\n\n")
  220.     Bladex.AddScheduledFunc(Bladex.GetTime()+60.0, CloseDeathFile, ())
  221.  
  222.     
  223.     muertonum = muertonum+1
  224.     
  225.  
  226. ############  Quake FX ############
  227.  
  228. def Let_temblOff():
  229.     cam = Bladex.GetEntity("Camera")
  230.     cam.EarthQuakeFactor = 0
  231.     cam.EarthQuake = 0
  232.  
  233. def Temblores(time,pianoforte=500):
  234.     cam = Bladex.GetEntity("Camera")
  235.     cam.EarthQuakeFactor = pianoforte
  236.     cam.EarthQuake = 1
  237.     Bladex.AddScheduledFunc(Bladex.GetTime()+time, Let_temblOff,())
  238.  
  239. ############  Max Camera Functions ############
  240.  
  241. def DetenLaCamaraDeLaConchaELaLora(Camera,frame):
  242.     import Scorer
  243.     cam = Bladex.GetEntity("Camera")
  244.     cam.SetPersonView("Player1")
  245.     cam.Cut()
  246.     Bladex.ActivateInput()
  247.     Scorer.SetVisible(1)
  248.     Bladex.SetListenerPosition(1)
  249.  
  250. def LaunchMaxCamera(CamName,Start,End,Funchi=DetenLaCamaraDeLaConchaELaLora):
  251.     import Scorer
  252.     cam = Bladex.GetEntity("Camera")
  253.     cam.SetMaxCamera(CamName,Start,End)
  254.     Scorer.SetVisible(0)
  255.     Bladex.SetListenerPosition(2)
  256.     Bladex.DeactivateInput()
  257.     cam.AddCameraEvent(-1,Funchi)
  258.  
  259. ############ Bad Guys funcs ############
  260. def HideObject(oname):
  261.     if oname:
  262.         obj = Bladex.GetEntity(oname)
  263.         obj.RemoveFromWorld()        
  264.         n_child=obj.GetNChildren()
  265.         for n in range(n_child):
  266.             HideObject(obj.GetChild(n))
  267.         
  268.  
  269. def UnhideObject(oname):
  270.     if oname:
  271.         obj = Bladex.GetEntity(oname)
  272.         obj.PutToWorld()        
  273.         n_child=obj.GetNChildren()
  274.         for n in range(n_child):
  275.             HideObject(obj.GetChild(n))
  276.             
  277.             
  278. def HideBadGuy(name,ciego=1,sordo=1):
  279.     pers = Bladex.GetEntity(name)
  280.     if not pers:
  281.         print "WARNING : Trying to hide `"+name+"`but was deleted !"
  282.         return
  283.     pers.Deaf  = sordo
  284.     pers.Blind = ciego
  285.     pers.Freeze()
  286.     pers.RemoveFromWorld()
  287.     HideObject(pers.InvLeft)
  288.     HideObject(pers.InvRight)
  289.     HideObject(pers.InvRightBack)
  290.     HideObject(pers.InvLeftBack)
  291.     HideObject(pers.InvLeft2)
  292.     char = Bladex.GetEntity("Player1")
  293.     if char.ActiveEnemy == name:
  294.         char.SetActiveEnemy("")
  295.         
  296.  
  297. def UnhideBadGuy(name):
  298.     pers = Bladex.GetEntity(name)
  299.     pers.Deaf  = 0
  300.     pers.Blind = 0
  301.     pers.UnFreeze()
  302.     pers.PutToWorld()
  303.     UnhideObject(pers.InvLeft)
  304.     UnhideObject(pers.InvRight)
  305.     UnhideObject(pers.InvRightBack)
  306.     UnhideObject(pers.InvLeftBack)
  307.     UnhideObject(pers.InvLeft2)
  308.  
  309.  
  310. ############ Hint Funcs ############
  311. def OnUse(entity, onuse ):
  312.   import GameText
  313.   GameText.WriteText(Bladex.GetEntity(entity).Data.MessageHint)
  314.  
  315. class EmptyClass:
  316.     pass
  317.  
  318.  
  319. def SetHint(gp,Name,OnUseData="",Priority=8.0,Distance=4000.0):
  320.     import MenuText
  321.     Reference.EntitiesSelectionData[gp.Name]=(Priority,Distance,MenuText.GetMenuText(Name))
  322.     
  323.     if type(OnUseData)==type(""):
  324.         if OnUseData != "":
  325.             gp.UseFunc          = OnUse
  326.             if not gp.Data:
  327.                 gp.Data = EmptyClass()
  328.             gp.Data.MessageHint = OnUseData
  329.     else:
  330.         gp.UseFunc = OnUseData
  331.  
  332. # SetHint(Bladex.GetEntity(char.InvRight),"Mierda","M7T4")
  333.  
  334. ############ Quake steps funcs (no rocketlauncher avail) ############
  335. QuakeFactor = 100
  336.  
  337. def QuakeStep(personaje):
  338.     global QuakeFactor
  339.     
  340.     cam = Bladex.GetEntity("Camera")
  341.     cam.EarthQuakeFactor = QuakeFactor
  342.     cam.EarthQuake = 1
  343.     Bladex.AddScheduledFunc(Bladex.GetTime()+0.125, QuakeHalf,())
  344.  
  345. def QuakeHalf():
  346.     QuakeStepCounter = 1
  347.     cam = Bladex.GetEntity("Camera")
  348.     cam.EarthQuakeFactor = cam.EarthQuakeFactor/2
  349.     Bladex.AddScheduledFunc(Bladex.GetTime()+0.125, QuakeStop,())
  350.  
  351. def QuakeStop():
  352.     QuakeStepCounter = 2
  353.     cam = Bladex.GetEntity("Camera")
  354.     cam.EarthQuakeFactor = 0
  355.     cam.EarthQuake = 0
  356.  
  357. ######## FIRE SECTORS #######
  358. FIRE_DAMAGE = 1
  359.  
  360. def QuemaTimer(e_name, time):
  361.   char = Bladex.GetEntity(e_name)
  362.   char.Life = char.Life - FIRE_DAMAGE
  363.   if char.Life <= 0:
  364.     Actions.FireDeath(e_name)
  365.     char.RemoveFromList("Timer15")
  366.     char.TimerFunc=""
  367.  
  368. def EntraQuema(triggername,entityname):
  369.   if entityname=="Player1":
  370.     char = Bladex.GetEntity("Player1")
  371.     char.SubscribeToList("Timer15")
  372.     char.TimerFunc=QuemaTimer
  373.  
  374. def SaleQuema(triggername,entityname):
  375.   if entityname=="Player1":
  376.     char = Bladex.GetEntity("Player1")
  377.     char.RemoveFromList("Timer15")
  378.     char.TimerFunc=""
  379.  
  380. ######  Assignation funcs ######
  381. def FireOnGS(name):
  382.     Bladex.SetTriggerSectorFunc(name, "OnEnter", EntraQuema )
  383.     Bladex.SetTriggerSectorFunc(name, "OnLeave", SaleQuema  )
  384.  
  385. def FireOnS(sec):
  386.         sec.OnEnter = EntraQuema
  387.         sec.OnLeave = SaleQuema
  388.  
  389. ######## NAILS DAMAGE ########
  390.  
  391. def EntraPincha(triggername,entityname):
  392.     import Scorer
  393.     ent = Bladex.GetEntity ( entityname )
  394.     if (ent.Person):
  395.         if entityname=="Player1":
  396.             Bladex.GetEntity("Camera").TType=0
  397.             AuxFuncs.FadeTo(1.0,60.0,32,0,0)
  398.             Scorer.SetVisible(0)
  399.         Bladex.AddScheduledFunc(Bladex.GetTime()+0.5, MuereDeVerdadPincha,(ent,))
  400.  
  401.         p = ent.Position
  402.         #Blood.BleedingImpact(ent , p[0], p[1], p[2],9999,0,0 )
  403.         #Blood.BleedingImpact(ent , p[0], p[1], p[2],9999,0,9999 )
  404.         #Blood.BleedingImpact(ent , p[0], p[1], p[2],3333,0,0 )
  405.         #Blood.BleedingImpact(ent , p[0], p[1], p[2],9999,0,3333 )
  406.         #Blood.BleedingImpact(ent , p[0], p[1], p[2],0,0,3333 )
  407.         #Blood.BleedingImpact(ent , p[0], p[1], p[2],0,0,9999 )
  408.         #Blood.BleedingImpact(ent , p[0], p[1], p[2],0,0,0 )
  409.  
  410. def MuereDeVerdadPincha(ent):        
  411.         ent.Life = 0
  412.         ent.Wuea = Reference.WUEA_ENDED
  413.         ent.SetTmpAnmFlags(1,1,1,0,5,1,0)
  414.         ent.LaunchAnmType("dth_rock")        
  415.         
  416. def NailOnGS(name):
  417.         Bladex.SetTriggerSectorFunc(name, "OnEnter", EntraPincha )
  418.  
  419. def NailOnS(sec):
  420.         sec.OnEnter = EntraPincha
  421.  
  422. ######## Enemy Deaths Detector #######
  423. class E_GroupAux:
  424.   ObjId=-1
  425.  
  426.   def __init__(self):
  427.     self.ObjId=ObjStore.GetNewId() # Para identificarlo al grabar/guardar
  428.     ObjStore.ObjectsStore[self.ObjId]=self
  429.  
  430.   def __del__(self):
  431.     del ObjStore.ObjectsStore[self.ObjId]
  432.  
  433.   def persistent_id(self):
  434.     return self.ObjId
  435.  
  436.   def __getitem__(self,key):
  437.     return self.__dict__[key]
  438.  
  439.   def __setitem__(self,key,value):
  440.     self.__dict__[key]=value
  441.  
  442.   def __getstate__(self):
  443.     return (1,self.ObjId)
  444.  
  445.   def __setstate__(self,parm):
  446.     if parm[0]==1:
  447.       self.ObjId=parm[1]
  448.       ObjStore.ObjectsStore[self.ObjId]=self
  449.  
  450.  
  451. class E_Grup:
  452.  
  453.     ObjId=0
  454.     n=0
  455.     OnDeath=None
  456.     Guys = []
  457.     ImDeadFuncs = None
  458.     
  459.     def __init__(self):
  460.         self.ObjId=ObjStore.GetNewId() # Para identificarlo al grabar/guardar
  461.         self.n           = 0    # Zero enemies
  462.         self.OnDeath     = None # No Callback
  463.         self.Guys        = []
  464.         self.ImDeadFuncs = E_GroupAux()
  465.         ObjStore.ObjectsStore[self.ObjId]=self
  466.  
  467.     def __del__(self):
  468.         del ObjStore.ObjectsStore[self.ObjId]
  469.  
  470.     def persistent_id(self):
  471.         return self.ObjId
  472.  
  473.     def ImDeadFunc(self,Name):
  474.         self.ImDeadFuncs["Ch_"+Name](Name)
  475.         self.n = self.n - 1
  476.         #print "Quedan",self.n
  477.         self.Guys.remove(Name)
  478.         if self.n == 0:
  479.             if self.OnDeath:
  480.                 self.OnDeath()
  481.             
  482.     def AddGuy(self,Name):
  483.         e                      = Bladex.GetEntity(Name)
  484.         self.ImDeadFuncs["Ch_"+Name] = e.ImDeadFunc
  485.         e.ImDeadFunc           = self.ImDeadFunc
  486.         self.n = self.n + 1
  487.         if Name in self.Guys:
  488.             print "E_Grup error : "+Name+" is allready here."
  489.         else:
  490.             self.Guys.append(Name)
  491.     
  492.     def HideBadGuys(self):
  493.         for Name in self.Guys:
  494.             HideBadGuy(Name)
  495.     
  496.     def UnhideBadGuys(self,number):
  497.         counter = 0
  498.         for Name in self.Guys:
  499.             counter = counter+1
  500.             UnhideBadGuy(Name)
  501.             if counter>=number:
  502.                 return counter
  503.         return counter
  504.     
  505.     def __getstate__(self):
  506.         # Tiene que devolver cΣ«» poder guardar el estado de la clase
  507.         ImDeadFuncsAux=[]
  508.         for i in self.ImDeadFuncs.__dict__.keys():
  509.             if i!="ObjId":
  510.                 ImDeadFuncsAux.append((i,GameStateAux.SaveFunctionAux( self.ImDeadFuncs[i] )))
  511.  
  512.         return (1,
  513.                     self.ObjId, # De GameStateAux.PersistentObject
  514.                     self.ImDeadFuncs,
  515.                     self.n,
  516.                     GameStateAux.SaveFunctionAux(self.OnDeath),
  517.                     self.Guys,
  518.                     ImDeadFuncsAux
  519.                 )
  520.  
  521.  
  522.     def __setstate__(self,parm):
  523.         # Toma como parΓ«Ñtro lo que devuelve __getstate__() y debe recrear la clase
  524.         
  525.         if parm[0]==1:
  526.             #self.ObjId=parm[1] En GameStateAux.PersistentObject()
  527. ##            GameStateAux.PersistentObject.__setstate__(self,parm)
  528.             self.ObjId=parm[1]
  529.             ObjStore.ObjectsStore[self.ObjId]=self
  530.             self.ImDeadFuncs=parm[2]
  531.             self.n=parm[3]
  532.             GameStateAux.LoadFunctionAux(parm[4],self,"OnDeath")
  533.             self.Guys=parm[5]
  534.             ImDeadFuncsAux=parm[6]
  535.             for i in ImDeadFuncsAux:
  536. ##                self.ImDeadFuncs[i[0]]=GameStateAux.LoadFunctionAux(i[1])
  537.                 GameStateAux.LoadFunctionAux(i[1],self.ImDeadFuncs,i[0])
  538.  
  539.  
  540.         else:
  541.             print "Door.__setstate__() -> Version mismatch"
  542.             # Valores por si valen para algo.
  543.             self.ObjId=ObjStore.GetNewId()
  544.             ObjStore.ObjectsStore[self.ObjId]=self
  545.             self.n           = 0    # Zero enemies
  546.             self.OnDeath     = None # No Callback
  547.             self.Guys        = []
  548.             self.ImDeadFuncs = E_GroupAux()
  549.  
  550. #----------------------------------------------------------------#
  551.  
  552. PersonasEnLlamas = []
  553.  
  554. def EnciendeEnLlamas(o,Intensity = 15,Precission=0.1):
  555.     global PersonasEnLlamas
  556.     
  557.     if not (o.Kind in PersonasEnLlamas):
  558.         PersonasEnLlamas.append(o.Kind)
  559.         Bladex.AddCombustionDataFor(o.Kind, "Fire", 250, 400, 4, 1, 3, 144000) # se extingira en 40 horas!
  560.     
  561.     o.SelfIlum = 0.0
  562.     o.CatchOnFire(0,0,0)
  563.     
  564.     luz             = Bladex.CreateEntity(o.Name+"Luz","Entity Spot",0,0,0)
  565.     luz.Color       = 200,100,0
  566.     luz.Intensity   = Intensity
  567.     luz.Precission  = Precission
  568.     luz.CastShadows = 0
  569.     luz.Visible     = 1
  570.     luz.SizeFactor  = 0
  571.  
  572.     o.Link(luz)
  573.  
  574. ### objetos Alfa ###
  575. def ObjAlpha(o,alpha=0.8,SelfIlum=0.0):
  576.     o.Alpha       = alpha
  577.     o.RasterMode  ="AdditiveAlpha"
  578.     o.RasterMode  ="Read"
  579.     o.CastShadows = 0
  580.     o.SelfIlum    = SelfIlum
  581.     
  582.     
  583.     
  584. #----------------------------------------------------------------#
  585. #  Funciones auxiliares para la aparicion valida de objetos      #
  586. #----------------------------------------------------------------#    
  587.  
  588. def ValidAppear(pos,func=None,param=None):
  589.     entid = Bladex.GetEntitiesAt(pos[0],pos[1],pos[2],4000)
  590.     for on in entid:
  591.         o = Bladex.GetEntity(on)
  592.         if o.Person:
  593.             if o.Life > 0:
  594.                 if o.Alpha >0.01:
  595.                     print "Trying to do it, but",on,"is bothering. Next try in 5 seconds."
  596.                     if func:
  597.                         Bladex.AddScheduledFunc(Bladex.GetTime()+5.0, ValidAppear,(pos,func,param))
  598.                     return 0
  599.     if func:
  600.         apply(func,param)
  601.         print "The function was XQted"
  602.     else:
  603.         return 1
  604.  
  605. def CreateFalseCube(pos,timeToKill = -1,Name = ""):
  606.     o = Bladex.CreateEntity(Name + "quad","Bloque",pos[0],pos[1]-1500,pos[2])
  607.     o.Orientation = (0.707107245922, 0.0, 0.0, 0.707106292248)
  608.     o.Scale = 4
  609.     o.CastShadows = 0
  610.     o.Alpha       = 0.0
  611.     o.RasterMode  ="Read"
  612.     if timeToKill != -1:
  613.         Bladex.AddScheduledFunc(Bladex.GetTime()+timeToKill, o.SubscribeToList,("Pin",))
  614.     return o
  615.     
  616.     
  617. #
  618. #  Destroy the pools and cadavres but the limbs and weapons, no.
  619. #----------------------------------------------------------------#    
  620. def CleanArea(x,y,z,radius):
  621.     list = Bladex.GetEntitiesAt(x,y,z,radius)
  622.     enCounter = 0
  623.     
  624.     for name in list:
  625.         o = Bladex.GetEntity(name)
  626.         if o.Kind == "Entity Pool":
  627.             o.SubscribeToList("Pin")
  628.         if o.Person:
  629.             if o.Life <= 0.0:
  630.                 if o.Name != "Player1":
  631.                     HideBadGuy(o.Name)
  632.                     enCounter = enCounter + 1
  633.     
  634.     return enCounter
  635.  
  636. #
  637. # Detects if a player joins into a sector
  638. #--------------------------------------------#
  639. def EnterSecEvent(x,y,z,func):    
  640.     sec = Bladex.GetSector(x,y,z)
  641.     EnterSecEventSector(sec,func)
  642.  
  643. def GetSectorIdx(pos):
  644.     if (type(pos)!=types.TupleType):
  645.         return pos
  646.     else:
  647.         return Bladex.GetSector(pos[0],pos[1],pos[2]).Index
  648.         
  649. def EnterSecIdEvent(id,func):
  650.     if type(id)==types.StringType:
  651.         EnterTSEvent(id,func)
  652.         return id
  653.     elif type(id)==types.TupleType:
  654.         sec = Bladex.GetSector(id[0],id[1],id[2])
  655.         EnterSecEventSector(sec,func)
  656.         return sec.Index
  657.     else:
  658.         sec = Bladex.GetSector(id)
  659.         EnterSecEventSector(sec,func)
  660.         return id
  661.  
  662. def EnterSecEventSector(sec,func):
  663.     global SectorTable
  664.  
  665.     if sec:
  666.         if not SectorTable.has_key(sec.Index):
  667.             if sec.OnEnter:
  668.                 print "ERROR : OnEnter Asigned to",sec.OnEnter
  669.             else:
  670.                 SectorTable[sec.Index]=[]
  671.         else:
  672.             numerox = len(SectorTable[sec.Index])
  673.             if numerox>0:
  674.                 if Reference.PYTHON_DEBUG >= 2:
  675.                     print "Warning : OnEnter have",numerox,"functions"
  676.             
  677.         SectorTable[sec.Index].insert(0,func)
  678.         sec.OnEnter = OnPlayerEnter
  679.         return sec.Index
  680.     else:
  681.         print "ERROR : Sector invalid!"
  682.     
  683. def OnPlayerEnter(sectorindex,entityname):
  684.     global SectorTable
  685.     
  686.     if entityname == "Player1":
  687.         funclist = []
  688.         
  689.         # guarda la lista de funciones a ejecutar
  690.         for f in SectorTable[sectorindex]:
  691.             funclist.append(f)
  692.         
  693.         # borra la lista y todo lo relacionado a ella
  694.         del SectorTable[sectorindex]
  695.         if type(sectorindex)==types.StringType:
  696.             Bladex.SetTriggerSectorFunc(sectorindex, "OnEnter", None )
  697.         else:
  698.             Bladex.GetSector(sectorindex).OnEnter = None
  699.         
  700.         # elimina las funciones que se llaman si se entra en mas de un sector
  701.         for f in funclist:
  702.             for key in SectorTable.keys():
  703.                 for e in SectorTable[key]:
  704.                     if e == f:
  705.                         SectorTable[key].remove(e)
  706.         
  707.         # ejecuta la lista de funciones en cuestion
  708.         for f in funclist:            
  709.             try:
  710.                 f()
  711.             except:
  712.                 f(sectorindex)
  713.     
  714.     
  715. SectorTable = {}
  716.  
  717. #
  718. ##   Ghost sector tools
  719. ####################################
  720. def EnterTSEvent(secname,func):
  721.     global SectorTable
  722.  
  723.     if secname:
  724.         if not SectorTable.has_key(secname):
  725.             if Bladex.GetTriggerSectorFunc(secname,"OnEnter"):
  726.                 print "ERROR : OnEnter Asigned to ",secname
  727.             else:
  728.                 SectorTable[secname]=[]
  729.         else:
  730.             numerox = len(SectorTable[secname])
  731.             if numerox>0:
  732.                 if Reference.PYTHON_DEBUG >= 2:
  733.                     print "Warning : OnEnter have",numerox,"functions"            
  734.         SectorTable[secname].insert(0,func)
  735.         Bladex.SetTriggerSectorFunc(secname, "OnEnter", OnPlayerEnter )        
  736.         return secname
  737.     else:
  738.         print "ERROR : Sector '"+secname+"' invalid!"
  739.  
  740. # darfuncs.EnterSecEvent(char.Position[0],char.Position[1],char.Position[2],x)
  741.  
  742.  
  743.  
  744.  
  745.  
  746.  
  747. ###
  748. ###  Template to make a clean in a area.
  749. ###
  750. ##import darfuncs
  751. ##
  752. ##def EntrayBorra():
  753. ##    darfuncs.CleanArea(clnX,clnY,clnZ,clnRadius)
  754. ##    
  755. ##darfuncs.EnterSecEvent(secX,secY,secZ,EntrayBorra)
  756.  
  757.  
  758.  
  759. def LuzChapuzera(light,FinishTime,delta = 1):
  760.     t = Bladex.GetTime()    
  761.     light.Move(0,0,delta)
  762.     if t<FinishTime:
  763.         Bladex.AddScheduledFunc(t+0.0, LuzChapuzera,(light,FinishTime,-delta))
  764.  
  765. ###
  766. ### Chapuza solution with the light cones
  767. ###
  768. ##
  769. ##darfuncs.LuzChapuzera(Bladex.GetEntity("luzbonita"), Bladex.GetTime() + 3.0) # mueve "luzbonita" durante 3 segundos
  770.  
  771.  
  772. def SaveData(filename):
  773.   import cPickle
  774.  
  775.   funcfile=open(filename,"wt")
  776.   p=cPickle.Pickler(funcfile)
  777.   d=(muertonum,ActualLevel,QuakeFactor,FIRE_DAMAGE,PersonasEnLlamas,SectorTable)
  778.   p.dump(d)
  779.   funcfile.close()
  780.  
  781.  
  782. def LoadData(filename):
  783.   import cPickle
  784.  
  785.   funcfile=open(filename,"rt")
  786.   p=cPickle.Unpickler(funcfile)
  787.   d=p.load()
  788.   funcfile.close()
  789.   print d
  790.  
  791.   global muertonum
  792.   global ActualLevel
  793.   global QuakeFactor
  794.   global FIRE_DAMAGE
  795.   global PersonasEnLlamas
  796.   global SectorTable
  797.   
  798.   muertonum=d[0]
  799.   ActualLevel=d[1]
  800.   QuakeFactor=d[2]
  801.   FIRE_DAMAGE=d[3]
  802.   PersonasEnLlamas=d[4]
  803.   SectorTable=d[5]
  804.  
  805.  
  806.  
  807. import GameState
  808. GameState.ModulesToBeSaved.append(__import__(__name__))
  809.